MODULE PARAMETERS

Implicit NONE 

Integer, Parameter :: dd = Selected_real_kind(15,307)


Integer, Parameter :: I_state_fix=3  
Integer, Parameter :: I_state_ht=2 

Integer, Parameter :: I_death=1       
Integer, Parameter :: I_EPHI=1   

Integer, Parameter :: n_experiments=9  
Real (Kind=dd), Parameter :: cat_ME=3.846153846d0  
Integer :: I_treat_Mcaid, I_sd_earn, I_s, I_du, I_dp, I_init_H, I_init_R, I_sick_days, I_wages_health, I_disutil_health, I_good_H, I_good_R, I_EPHI_all, I_EPHI_none, I_med_exp, I_med_exp_s, I_med_exp_du, I_med_exp_dp, I_Col_R, I_Col_H, I_Col_dp , I_med_exp_G, I_sd_HC, I_MEcat

Real (Kind=dd), dimension (2)::  param_calib 

!****** health insurance experiments
Real (Kind=dd) :: copay_hi  
Real (Kind=dd) :: copay_phi  
Real (Kind=dd) :: premium_phi  


Real (Kind=dd) :: treat_age_adj ! parameter to adjust probability of "can't treat" set for uninsrued at older ages
Real (Kind=dd), dimension (3):: c_floor_age_adj_young
Real (Kind=dd), dimension (3):: c_floor_age_adj_old


!Demographics 
Integer, Parameter :: n_e=3        !There are 3 education groups: 1 = HS dropouts & HS Graduate, 2= some college; 3= college graduate
Integer, Parameter :: n_age=76     !This is the max age to which a person lives (1=25, 76=100)   ( 26=50)
Integer, Parameter :: n_ret= 41      !Everybody retires at age 65 (41=65) 
Integer, Parameter :: n_hc=39  

Real (Kind=dd), dimension (0:n_hc):: HK


Integer, Parameter :: n_hc_grid=5     !This is the max number of grid points for human capital, for any age. (more grid points for older ages)
Integer, parameter :: n_sample=30000  !The number of individuals simulated

!Employment offers
Integer, Parameter :: n_o=5        !1=no offer, 2=PT, no ins, 3=PT, ins, 4=FT, no ins, 5=FT, ins
Integer, Parameter :: n_os=2  ! spouse's employment: 1=not work, 2=work 
Integer, Parameter :: n_past_o=2   

!Number of income groups for the H and R probabilities
Integer, Parameter :: n_inc=5

Integer, Parameter :: n_trpay=3 ! 1 = pay and get treated; 2=don't pay, get treated; 3=don't pay, not treated.
Real (Kind=dd), dimension (3,n_o,3,n_ret-1) ::  Shock_type ! (1=cannot treat, 2= can treat, but no default, 3=must treat, can default); 
! 1 = you only have options  trpay = 1 or 3 
! 2 = you have all 3 options
! 3= you only have options 1 and 2. 
Real (Kind=dd) :: Prob_no_treat ! probability that you cannot treat when you're uninsured conditional on that you are not in "Prob_option_pay(3)" where you have to treat.

!Assets and savings
Real (Kind=dd), Parameter :: gridcurv=3.3d0        !Grid for assets (curvature)
Integer, Parameter :: n_sav=11     !number of grid points for savings
Integer, Parameter :: n_sav_sim=74 !in the simulation, we use a finer grid for savings
Integer, Parameter :: n_as=12        !number of grid points for assets. This is what you carry to next period.

Real (Kind=dd), dimension (n_o, n_sav) :: sav 
Real (Kind=dd), dimension (n_sav) :: sav_ret  
Real (Kind=dd), dimension (n_sav) :: sav_grid

Real (Kind=dd), dimension (n_sav_sim) :: sav_sim
Real (Kind=dd), dimension (n_sav_sim) :: sav_grid_sim


Integer, Parameter :: n_mar=2

 Real (Kind=dd), dimension (n_e):: assets_initial
         
Integer, Parameter :: n_DI=2      !1- no DI; 2- has DI
Integer, Parameter :: n_h=3       !Number of health states: ranges from 1-3: 1=poor, 2=fair, 3=good 
Integer, Parameter :: n_r=2       !Number of risk factor states: 1=low risk, 2=high risk
Integer, Parameter :: n_du=2      !Grid for du : 1= no shock, 2=get a du shock
Integer, Parameter :: n_dp=2      !Grid for dp
Integer, Parameter :: n_s=2       !Grid for su
Integer, Parameter :: n_ht=2      !Grid for latent health types. 1=good , 2= Bad latent type
Integer, Parameter :: n_type1=18  !Grid for educ x permanent productivity type x permanent "healthy type" (3x3x2)
Integer, Parameter :: n_type2=8   !Grid for du x dp x s  (all possible combinations of health shocks)
Integer, Parameter :: n_type3=6   !Grid for HxR (9) + H=1 with DI xR (3) =12
!Wages and SS
Integer, Parameter :: n_fix=3      !Fixed productivity shock (determined at entry into the labor force)
Integer, Parameter :: n_hc_ret=3   !human capital categories at 64
Integer, Parameter :: n_zt=3       !Transitory shocks

Integer, Parameter :: n_type4 = 3 ! 1=single, 2=married, spouse not working, 3=married, spouse working

Real (Kind=dd), dimension (2, n_ht) :: H25_adj 
Real (Kind=dd), dimension (n_e, n_ht) :: R25_adj  


! leisure
Real (Kind=dd), dimension (n_e,n_o,n_h,n_type2) :: leis 

Real (Kind=dd), parameter ::  hrs_ft =0.4d0
Real (Kind=dd), parameter ::  hrs_pt =0.2d0
Real (Kind=dd), dimension (n_o) :: hrs_offer

Integer, Parameter :: n_zhc=1

Integer, Parameter :: t_hc=41   

Real (Kind=dd), dimension (n_as, n_type1,n_age) :: as 
Integer, Parameter :: n_spouse=1 
Integer, Parameter :: n_MEcat=2  ! 1= regular, 2=catastrophic

Real (Kind=dd), dimension (1:n_ret-1) ::max_age_HC



Real (Kind=dd), dimension (n_MEcat) :: Prob_MEcat 
Real (Kind=dd), dimension (n_e,n_DI) :: p_DI 

!Preferences
Real (Kind=dd) :: cost_death
Real (Kind=dd) :: vl               !Value of life
Real (Kind=dd) :: sigma
Real (Kind=dd) :: alpha
Real (Kind=dd) :: gamma
Real (Kind=dd), dimension(3,n_o) :: eta 
Real (Kind=dd), dimension(n_e) :: beta_hat       
! bequest parameters
Real (Kind=dd) :: theta_beq
Real (Kind=dd) :: k_beq
Real (Kind=dd) :: sig_beq
Real (Kind=dd), dimension(n_e,n_age) :: equiv

!Initial distribution of H and R
Real (Kind=dd), dimension(n_e,n_h,n_ht) :: In_h
Real (Kind=dd), dimension(n_e,n_r) :: In_r
Real (Kind=dd), dimension(n_e,n_h,2) :: In_h_ht 
Real (Kind=dd), dimension(n_e,n_r,2) :: In_r_ht
Real (Kind=dd), dimension(n_type1) :: In_type1 
Real (Kind=dd), dimension(n_e,n_fix) :: In_ht 
Real (Kind=dd), dimension(n_e,n_h) :: In_mar 

!Transitions for H
Real (Kind=dd), dimension(n_h,  n_h,n_e,n_ht, n_age, n_type2,2,4):: Tp_h 

Real (Kind=dd), dimension(n_h, n_h, n_e, 2, n_age, n_dp, n_du, 1:5):: trprob_h ! this is an intermediate matrix
Real (Kind=dd), dimension(n_h,n_e,n_mar,n_age) :: p_surv
Real (Kind=dd), dimension(n_r,n_r,n_age, n_h) :: p_risk
Real (Kind=dd), dimension(n_e,n_type2, n_h, n_r, n_age) :: shocks_risk
Real (Kind=dd), dimension(n_type2, n_h, n_age, n_MEcat,n_o) :: oop 
Real (Kind=dd), dimension(n_age,n_e, n_type4,n_o) :: oop_spouse
Real (Kind=dd), dimension(n_type2, n_h, n_ret-1, n_MEcat) :: Charges ! these don't depend on insurance. 


Real (Kind=dd), dimension(n_e, n_h,n_type2) :: phi  

Real (Kind=dd), dimension(n_h,n_type2) :: phi_nw 

Real (Kind=dd), dimension(n_e,n_o,2) :: leis_mar

! OTHER PARAMETERS
Real (Kind=dd) :: interest         !Interest rate
Real (Kind=dd) :: taxc             !Consumption tax
Real (Kind=dd) :: taxc_hi          !Additional Consumption tax needed to balance the budget when we give public health insurance to <65. this tax is imposed only on those <65
Real (Kind=dd) :: tau_ss           !Tax for social security 
Real (Kind=dd) :: tau_med          !Medicare tax   
Real (Kind=dd), dimension(2) ::  tax_lambda        ! Parameter in tax function, depends on marital status
Real (Kind=dd), dimension(2) ::  tax_tau        ! Parameter in tax function, depends on marital status
Real (Kind=dd), dimension(n_age,n_mar,n_e, n_h) :: cons_floor,  cons_floor_at ! this is just to read the cons floor for all educ groups 
Real (Kind=dd), dimension(n_e) :: c_floor_adjust_mar ! this parameter adjust the consumption floor of the married.

Real (Kind=dd) :: yhat             !Maximum taxable earnings  for social security
Real (Kind=dd) :: penalty          !A very low number to guarantee people consume positive amounts and do not borrow
Real (Kind=dd), dimension(n_e) ::  p_e   !Proportion in each education group
Real (Kind=dd), dimension(n_hc_ret, n_e, n_fix) ::  pen   

Real (Kind=dd), dimension(n_o,n_type4) :: prem_ephi        
Real (Kind=dd), dimension(2) :: prem_mcare       ! Medicare premium (part B) - paid by those over 65. 1= for singles, 2=for married (this is 2 x singles)

!Wages  
Real (Kind=dd), dimension (n_e) ::  varzfix, stdzfix   , varzt, stdzt , rho, stdinno , varinno, stdze  !variance and sd of the fixed and transitory wage shocks
!Coefficients determining the deterministic compoenent of wages
Real (Kind=dd), dimension (n_e) ::	  b0
Real (Kind=dd), dimension (n_e) ::	  b1 ! HC 
Real (Kind=dd), dimension (n_e) ::	  b2 ! HC^2
Real (Kind=dd), dimension (n_e) ::	  b3 ! HC^3
Real (Kind=dd), dimension (n_e) ::	  b4 ! H=avg 
Real (Kind=dd), dimension (n_e) ::	  b5 ! H=good 
Real (Kind=dd), dimension (n_e) ::	  b6 ! not employed last year

Real (Kind=dd), dimension (n_e) ::	 PT_penalty
Real (Kind=dd), dimension (n_o, n_e) :: wage_penalty 
Real (Kind=dd) :: delta
Real (Kind=dd) :: delta_hc
Real (Kind=dd), dimension (n_e) :: delta_hc_read
Real (Kind=dd), dimension (n_ret) :: ws ! this is a vector of ones, except in experiments where we increase wages at various ages for everyone by say 20%


Real (Kind=dd), dimension (n_e,n_zt,2) :: p_zt             ! Probabilities of transitory shocks.  For the last argument, 1= not employed last year, and 2= employed last year. If employed last year, transitory shocks have mean zero. but if not employed last year, the mean is lower and we use beta(6) in the wage funtion which tells us how much lower
Real (Kind=dd), dimension (n_e,n_zt) :: zt               ! Transitory shocks
Real (Kind=dd), dimension (n_e,n_fix) :: p_fix           ! Probabilities of the fixed productivity type
Real (Kind=dd), dimension (n_e,n_fix) :: zfix            ! The individual fixed effects
Real (Kind=dd), dimension (n_e, 0:n_hc, n_h,n_o) :: zd_sim       ! The deterministic component of z
Real (Kind=dd), dimension (n_e, 0:n_hc, n_h) :: zd       ! The deterministic component of z

Real (Kind=dd), dimension (0:n_hc,n_h,n_e,n_fix,n_zt,n_o) :: z_sim ! in the simulation, we can let z depend on lagged o. 
Real (Kind=dd), dimension (0:n_hc,n_h,n_e,n_fix,n_zt) :: z ! Efficiency units
!Real (Kind=dd) :: hrs_ft                                 ! This is h*(FT) - Number of hours of healthy full timers - can be 40 hrs per week, or a bit more to make it consistent with average hours in the data
!Real (Kind=dd) :: hrs_pt                                 ! This is h*(PT) - Number of hours of healthy part timers - around 20
Real (Kind=dd), dimension (0:n_hc,n_h,n_e,n_fix,n_zt,n_o)  :: base_earn  ! base earnings - for ft and full time (so wages*hours) but not taking into account sick days.

!Shocks to HC
Real (Kind=dd), dimension (n_e,n_o,n_zhc) :: p_zhc         
Real (Kind=dd), dimension (n_zhc) :: zhc            
Real (Kind=dd), dimension (n_e) :: stdzhc              
!Employment offers
Real (Kind=dd), dimension(n_o,n_o,n_e,n_ret-1) :: Pr_o_i ! The probability of each wage offer "o" 
Real (Kind=dd), dimension(n_o,n_e) :: Pr_o_25    ! Initial probablity at 25
Real (Kind=dd), dimension (n_e,2) :: delta_o ! the linear trend determining the increase in the probability of getting no offer with age, after 54.
Real (Kind=dd), dimension (n_e,6) :: param_o_trans 

!OTHERS
Real (Kind=dd) :: y_bar                       !This is a cap on income taxes
Real (Kind=dd), dimension (n_h, n_type2, n_age) :: beta   !Actual discount factor that takes into account survival
Real (Kind=dd), dimension (n_type1) :: n_samp  ! number individuals simulated 


Real (Kind=dd), dimension (n_hc_grid, n_ret-1) :: xfn, agex
Integer, dimension (n_ret-1) :: hk_gp ! this function gives the number of hk grid points used at every age.  
    

  Real (Kind=dd), dimension (n_inc-1) :: INC_TS


Real (Kind=dd), dimension (n_e,n_h)::  FT_fc ,   PT_fc

    integer, parameter:: dbl = kind(1d0)   
    real(dbl), parameter:: pi = 3.14159265358979d0
    character(1), parameter:: tab = char(9)
    
Real (Kind=dd), dimension (n_mar,n_mar, n_e,n_age,n_h,n_inc,n_o) :: Tp_mar   
Real (Kind=dd), dimension (n_age,n_e,n_h,n_type4,n_fix) :: inc_spouse  ! this can include the social security income of those retired
Real (Kind=dd), dimension (n_ret-1,n_e,n_h,n_os,n_fix) :: prob_os ! brobability spouse works

Real (Kind=dd), dimension (n_e,n_fix) :: prob_os_skill
Real (Kind=dd), dimension (n_e,n_fix,2:3) :: inc_spouse_skill ! the last one is for jtype4=2 and jtype4=3 (spouse does not work and spouse works)

! for R
CHARACTER(80) :: flname2
Real (Kind=dd), dimension (7) :: param_r


! for H:
Real (Kind=dd), dimension (2) :: param_h_cutoff_A, param_h_cutoff_B
Real (Kind=dd), dimension (14) :: param_h

!this will be used both in VF and simulation
Real (Kind=dd), dimension (5,n_ret-1, n_o,n_e,n_ht,n_type3,n_type2,n_o,n_type3,n_zhc) :: prob_s_treat_new

!probability of reporting shocks and R if not treated
Real (Kind=dd), dimension (1:n_h,3,2) :: neu_shocks ! the second argument is for the 3 shocks. 1=dp, 2=du, 3=s.  last argument is for treat or not treat
Real (Kind=dd), dimension (n_o) :: neu_R ! for convenience, we have it as function of jo. But only insurance matters, i.e., 1,2,4 vs 3,5

Real (Kind=dd), dimension (3) :: MC_TS
Real (Kind=dd), dimension (2,n_e) :: hc_TS
     
Real :: time1, time2, time3, time4, time5, time
    END MODULE PARAMETERS
    
    

